package com.googlecode.genie5day;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import java.util.Calendar;

public class UpdateService extends Service {
    private static final String TAG = "UpdateService";

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e(TAG, "Received start id " + startId + ": " + intent);
        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
       /*
        new Thread(new Runnable() {
            public void run() {
                try {
                    Log.e(TAG, "starting parser");
                    ForecastParser parser = new ForecastParser();
                    Calendar cal = Calendar.getInstance();
                    cal.set(Calendar.MINUTE, 0);
                    cal.set(Calendar.SECOND, 0);
                    cal.set(Calendar.MILLISECOND, 0);
                    Log.i(TAG, "cal day: " + cal.get(Calendar.DAY_OF_YEAR));
                    Forecast forecast = parser.getForecast((Calendar) cal.clone());
                    // PSK HACK for now
                    Forecast.setCurrentForecast( forecast );

                    ForecastDetail detail = forecast.getCurrentDetail(cal);
                    Log.e(TAG,"parsedForecast  current detail: " + detail);

                    Intent intent = new Intent(Widget.INTENT_NEW_FORECAST, null);
                    intent.putExtra("temp", detail.getTemp());
                    intent.putExtra("windSpeed", detail.getWindSpeed());
                    intent.putExtra("windDirection", detail.getWindDirection());
                    sendBroadcast(intent);
                }
                catch (Exception e) {
                    Log.e(TAG, "error parsing forecast", e);
                }
            }
        } ).start();
        */
        return START_STICKY;
    }

}
